package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.ColdStorageTempEntity;

/**
 * 冷藏临时出藏记录表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class ColdStorageTempProvider {

    /**
     * 增加ColdStorageTemp
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertColdStorageTemp(@Param("entity") ColdStorageTempEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cold_storage_temp ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" cold_storage_id ", " #{entity.coldStorageId,jdbcType=INTEGER} ");

                if (entity.getTempWhereaboutsCode() != null) {
                    VALUES(" temp_whereabouts_code ", " #{entity.tempWhereaboutsCode,jdbcType=TINYINT} ");
                }

                VALUES(" temp_out_time ", " #{entity.tempOutTime,jdbcType=TIMESTAMP} ");
                VALUES(" temp_return_time ", " #{entity.tempReturnTime,jdbcType=TIMESTAMP} ");

                if (entity.getAsReturned() != null) {
                    VALUES(" as_returned ", " #{entity.asReturned,jdbcType=TINYINT} ");
                }

                VALUES(" random_code ", " #{entity.randomCode,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ColdStorageTemp
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateColdStorageTemp(@Param("entity") ColdStorageTempEntity entity) {
        return new SQL() {
            {
                UPDATE(" cold_storage_temp ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" cold_storage_id = #{entity.coldStorageId,jdbcType=INTEGER} ");

                if (entity.getTempWhereaboutsCode() != null) {
                    SET(" temp_whereabouts_code = #{entity.tempWhereaboutsCode,jdbcType=TINYINT} ");
                }

                SET(" temp_out_time = #{entity.tempOutTime,jdbcType=TIMESTAMP} ");
                SET(" temp_return_time = #{entity.tempReturnTime,jdbcType=TIMESTAMP} ");

                if (entity.getAsReturned() != null) {
                    SET(" as_returned = #{entity.asReturned,jdbcType=TINYINT} ");
                }

                SET(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ColdStorageTemp列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listColdStorageTemp(@Param("entity") ColdStorageTempEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,cold_storage_id,temp_whereabouts_code,temp_out_time,temp_return_time,as_returned,random_code,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cold_storage_temp ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getColdStorageId() != null) {
                    WHERE(" cold_storage_id = #{entity.coldStorageId,jdbcType=INTEGER} ");
                }

                if (entity.getTempWhereaboutsCode() != null) {
                    WHERE(" temp_whereabouts_code = #{entity.tempWhereaboutsCode,jdbcType=TINYINT} ");
                }

                if (entity.getTempOutTime() != null) {
                    WHERE(" temp_out_time = #{entity.tempOutTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getTempReturnTime() != null) {
                    WHERE(" temp_return_time = #{entity.tempReturnTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getAsReturned() != null) {
                    WHERE(" as_returned = #{entity.asReturned,jdbcType=TINYINT} ");
                }

                if (entity.getRandomCode() != null) {
                    WHERE(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}